package com.atguigu.cmsservice.controller;


import com.atguigu.cmsservice.entity.CrmBanner;
import com.atguigu.cmsservice.service.CrmBannerService;
import com.atguigu.commonutils.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 首页banner表 前端控制器
 * </p>
 *
 * @author thomasyang
 * @since 2023-12-15
 */

@CrossOrigin
@RestController
@RequestMapping("/cmsservice/banneradmin")
public class BannerAdminController {


    @Autowired
    private CrmBannerService bannerService;
    //1 获取Banner分页列表
    @ApiOperation(value = "获取Banner分页列表")
    @GetMapping("{page}/{limit}")
    public R getIndex(@PathVariable Long page, @PathVariable Long limit){

        Page<CrmBanner> pageBanner = new Page<>(page, limit);
        bannerService.page(pageBanner, null);

        return R.ok().data(pageBanner);

    }

    //2 添加banner
    @ApiOperation(value="添加banner")
    @PostMapping("save")
    public R addbanner(@RequestBody CrmBanner banner){

        boolean save = bannerService.save(banner);

        return R.flagCheck(save);
    }
    //3 获取banner
    @ApiOperation(value="获取banner")
    @GetMapping("get/{id}")
    public R getBanner(@PathVariable String id){

        CrmBanner banner = bannerService.getById(id);

        return  R.ok().data(banner);
    }

    //4 更新banner
    @ApiOperation(value="更新banner")
    @GetMapping("update")
    public R updateBannerById(@RequestBody CrmBanner banner){

        boolean update = bannerService.updateById(banner);

        return R.flagCheck(update);

    }

    //5 删除banner
    @ApiOperation(value="删除banner")
    @DeleteMapping("remove/{id}")
    public R removeBannerById(@PathVariable String id){

        boolean remove = bannerService.removeById(id);

        return R.flagCheck(remove);
    }

}

